import { reactive } from 'vue';
import { addProjectToSchedules } from 'utils/utils';

export default function () {
  let state = reactive({
    task: {
      date: new Date(),
      dateDisplayed: '',
      learning: '',
      review: '',
    },

    projects: [],
    schedules: {},
  });

  const { schedules } = state;
  try {
    let projects = JSON.parse(localStorage.getItem('projects'));
    projects.forEach((project) => {
      addProjectToSchedules(project, schedules);
    });
    state.projects = projects;
  } catch (e) {
    state.projects = [];
  }

  return {
    state,
  };
}
